package com.baosight.sczx.zm.cs.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ef.ui.tree.TreeConstants;
import com.baosight.iplat4j.ef.ui.tree.TreeService;
import com.baosight.iplat4j.ep.QueryMap;

/**
 * 工程设置 树
 * <p>Title: ServiceZMCS80.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-9-1 上午06:49:19  严洪浩  Create
 *</pre>
 */
public class ServiceZMCS80 extends TreeService {
	
	
	/**
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 路涛
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public EiInfo query(EiInfo inInfo) {
		QueryMap queryInfo = QueryMap.getQueryMap(inInfo);
		String p = (String) queryInfo.get(TreeConstants.TREE_NODE);
		List children = new ArrayList();
		if (p == null) {
			p = "$";
		}
		if ("$".equals(p)) {
			children = this.getTopNodes();
		} else {
			children = this.getChildNode(queryInfo);
		}

		EiInfo outInfo = new EiInfo();
		EiBlock block = outInfo.addBlock(p);
		block.setBlockMeta(initMetaData());
		block.setRows(children);
		return outInfo;
	}
	
	/**获取子节点
	 * <p>Function: getChildNode</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 路涛
	 * </p>
	 *
	 */
	public List<Map<String, String>> getChildNode(QueryMap queryInfo) {
		String parentTypes = (String)queryInfo.get("parentTypes");//大类0采煤 1掘进 2通防 3其他
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		
		if("0".equals(parentTypes)) {
			//采煤
			list = this.CMList();
		}
		else if("1".equals(parentTypes)) {
			//掘进
			list = this.JJList();
		}
		else if("2".equals(parentTypes)) {
			//通防
			list = this.TFList();
		}
		else {
			//其他
			list = this.QTList();
		}

		return list;
	}
	
	/**
	 * <p>Function: getChildNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 路涛
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes" })
	@Override
	public List getChildNodes(String arg0) {
		return null;
	}

	/**
	 * 系统模块树结构：得到根节点数据
	 * <p>Function: getTopNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS01</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-11上午10:11:05 严洪浩
	 * </p>
	 *
	 */

	@Override
	public List<Map<String, String>> getTopNodes() {
		List<Map<String, String>> _topNodes = new ArrayList<Map<String, String>>();

		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("value", "CM");
		_tempMap.put("display", "采煤");
		_tempMap.put("parentTypes", "0");
		_tempMap.put("childTypes", "0");
		_tempMap.put("isLeaf", "0");
		_topNodes.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "JJ");
		_tempMap.put("display", "掘进");
		_tempMap.put("parentTypes", "1");
		_tempMap.put("childTypes", "0");
		_tempMap.put("isLeaf", "0");
		_topNodes.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "TF");
		_tempMap.put("display", "通防");
		_tempMap.put("parentTypes", "2");
		_tempMap.put("childTypes", "0");
		_tempMap.put("isLeaf", "0");
		_topNodes.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "QT");
		_tempMap.put("display", "其他");
		_tempMap.put("parentTypes", "3");
		_tempMap.put("childTypes", "0");
		_tempMap.put("isLeaf", "0");
		_topNodes.add(_tempMap);
		
		return _topNodes;
	}
	
	/**
	 * 采煤的二级分类
	 * <p>Function: CMList</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map<String,String>></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-1上午08:15:23 严洪浩
	 * </p>
	 *
	 */
	private List<Map<String, String>> CMList() {
		List<Map<String, String>> _list = new ArrayList<Map<String, String>>();
		
		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("value", "ZC");
		_tempMap.put("display", "综采");
		_tempMap.put("parentTypes", "0");
		_tempMap.put("childTypes", "综采");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "LC");
		_tempMap.put("display", "连采");
		_tempMap.put("parentTypes", "0");
		_tempMap.put("childTypes", "连采");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "JC");
		_tempMap.put("display", "机采");
		_tempMap.put("parentTypes", "0");
		_tempMap.put("childTypes", "机采");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "PC");
		_tempMap.put("display", "炮采");
		_tempMap.put("parentTypes", "0");
		_tempMap.put("childTypes", "炮采");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		return _list;
	}
	
	/**
	 * 掘进的二级分类
	 * <p>Function: CMList</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map<String,String>></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-1上午08:15:23 严洪浩
	 * </p>
	 *
	 */
	private List<Map<String, String>> JJList() {
		List<Map<String, String>> _list = new ArrayList<Map<String, String>>();
		
		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("value", "KT");
		_tempMap.put("display", "开拓");
		_tempMap.put("parentTypes", "1");
		_tempMap.put("childTypes", "开拓");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "HC");
		_tempMap.put("display", "回采");
		_tempMap.put("parentTypes", "1");
		_tempMap.put("childTypes", "回采");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "WSZL");
		_tempMap.put("display", "瓦斯治理");
		_tempMap.put("parentTypes", "1");
		_tempMap.put("childTypes", "瓦斯治理");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		return _list;
	}
	
	/**
	 * 通防的二级分类
	 * <p>Function: CMList</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map<String,String>></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-1上午08:15:23 严洪浩
	 * </p>
	 *
	 */
	private List<Map<String, String>> TFList() {
		List<Map<String, String>> _list = new ArrayList<Map<String, String>>();
		
		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("value", "DZ");
		_tempMap.put("display", "打钻");
		_tempMap.put("parentTypes", "2");
		_tempMap.put("childTypes", "打钻");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "CC");
		_tempMap.put("display", "抽采");
		_tempMap.put("parentTypes", "2");
		_tempMap.put("childTypes", "抽采");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "GLAZ");
		_tempMap.put("display", "管路安装");
		_tempMap.put("parentTypes", "2");
		_tempMap.put("childTypes", "管路安装");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "SLCK");
		_tempMap.put("display", "水力冲孔");
		_tempMap.put("parentTypes", "2");
		_tempMap.put("childTypes", "水力冲孔");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		return _list;
	}
	
	
	/**
	 * 其他的二级分类
	 * <p>Function: CMList</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map<String,String>></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-1上午08:15:23 严洪浩
	 * </p>
	 *
	 */
	private List<Map<String, String>> QTList() {
		List<Map<String, String>> _list = new ArrayList<Map<String, String>>();
		
		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("value", "XX");
		_tempMap.put("display", "巷修");
		_tempMap.put("parentTypes", "3");
		_tempMap.put("childTypes", "巷修");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "AC");
		_tempMap.put("display", "按拆");
		_tempMap.put("parentTypes", "3");
		_tempMap.put("childTypes", "按拆");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "LX");
		_tempMap.put("display", "零星");
		_tempMap.put("parentTypes", "3");
		_tempMap.put("childTypes", "零星");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "PJ");
		_tempMap.put("display", "喷浆");
		_tempMap.put("parentTypes", "3");
		_tempMap.put("childTypes", "喷浆");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "WD");
		_tempMap.put("display", "卧底");
		_tempMap.put("parentTypes", "3");
		_tempMap.put("childTypes", "卧底");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("value", "QTQT");
		_tempMap.put("display", "其他");
		_tempMap.put("parentTypes", "3");
		_tempMap.put("childTypes", "其他");
		_tempMap.put("isLeaf", "1");
		_list.add(_tempMap);
		
		return _list;
	}
	
	/**
	 * 列定义
	 * <p>Function: initMetaData</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS80</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-1上午06:53:26 严洪浩
	 * </p>
	 *
	 */
	@Override
	public EiBlockMeta initMetaData() {
		EiBlockMeta eiMetadata = new EiBlockMeta();

		EiColumn eiColumn = new EiColumn("value");
		eiColumn.setDescName("ID");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("display");
		eiColumn.setDescName("名称");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("parentTypes");
		eiColumn.setDescName("大类");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("childTypes");
		eiColumn.setDescName("小类");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("isLeaf");
		eiColumn.setDescName("是否叶子");
		eiColumn.setType(EiConstant.COLUMN_TYPE_NUMBER);
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		return eiMetadata;
	}
}
